simple_mtglife

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