simple_mtglife
view mainwin.cc @ 4:7cac97dca573
added coin flip
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 26 Jan 2015 07:48:56 +0200 |
parents | d76fb2ffe7f5 |
children |
line source
1 #include <random>
2 #include <QMessageBox>
3 #include "mainwin.h"
4 #include "ui_mainwin.h"
6 MainWin::MainWin(QWidget *parent) :
7 QMainWindow(parent),
8 ui(new Ui::MainWin)
9 {
10 ui->setupUi(this);
11 }
13 MainWin::~MainWin()
14 {
15 delete ui;
16 }
18 void MainWin::on_bn_p1_reset_clicked()
19 {
20 ui->spin_p1_life->setValue(20);
21 }
23 void MainWin::on_bn_p2_reset_clicked()
24 {
25 ui->spin_p2_life->setValue(20);
26 }
28 void MainWin::on_bn_p1_inc10_clicked()
29 {
30 ui->spin_p1_life->setValue(ui->spin_p1_life->value() + 10);
31 }
33 void MainWin::on_bn_p1_dec10_clicked()
34 {
35 ui->spin_p1_life->setValue(ui->spin_p1_life->value() - 10);
36 }
38 void MainWin::on_bn_p2_inc10_clicked()
39 {
40 ui->spin_p2_life->setValue(ui->spin_p2_life->value() + 10);
41 }
43 void MainWin::on_bn_p2_dec10_clicked()
44 {
45 ui->spin_p2_life->setValue(ui->spin_p2_life->value() - 10);
46 }
48 void MainWin::on_action_reset_triggered()
49 {
50 on_bn_p1_reset_clicked();
51 on_bn_p2_reset_clicked();
52 }
54 void MainWin::on_action_quit_triggered()
55 {
56 QApplication::quit();
57 }
59 void MainWin::on_action_about_triggered()
60 {
61 static const char *about_text =
62 "simple_mtglife is an extremely simple and lightweight life counter "
63 "for magic: the gathering.\n"
64 "\n"
65 "Copyright (C) 2015 John Tsiombikas <nuclear@member.fsf.org>\n"
66 "http://nuclear.mutantstargoat.com\n"
67 "\n"
68 "This program is free software. Feel free to copy, modify, and "
69 "distribute copies of this application, under the terms of the "
70 "GNU General Public License version 3 (or any later version).";
71 QMessageBox::about(this, "About simple_mtglife", about_text);
72 }
74 void MainWin::on_action_flip_coin_triggered()
75 {
76 static std::mt19937 gen;
77 static std::bernoulli_distribution distr(0.5);
78 bool res = distr(gen);
80 QMessageBox msg;
81 msg.setText(res ? "<big>heads!</big>" : "<big>tails!</big>");
82 msg.setIconPixmap(QPixmap(res ? ":data/mtg_heads.png" : ":data/mtg_tails.png"));
83 msg.setWindowTitle("Coin flip");
84 msg.setModal(true);
85 msg.exec();
86 }